<template>
    <div class="goodslist-container">
        <router-link :to="'/home/goodsInfo/'+item.id" class="goodsitem" v-for="item in goodsList" :key="item.id">
            <img :src=" item.img_url" alt="">
            <h1 class="title">{{ item.title }} </h1>
            <div class="goodsinfo">
                <p class="price">
                    <span class="newPrice">{{ item.sell_price }}</span>
                    <span class="oldPrice">{{ item.market_price }}</span>
                </p>
                <p class="sell">
                    <span>热卖中</span>
                    <span>剩余{{ item.stock_quantity}}件</span>
                </p>
            </div>
        </router-link>
        <mt-button type="danger" size="large" @click="getmore()">加载更多</mt-button>
    </div>
</template>
<script>
export default {
    data() {
        return {
            goodsList:[],
            pageindex:1,
        }
    },
    created(){
        this.getGoodsList();
    },
    methods:{
        getGoodsList(){
            this.$http.get("http://www.liulongbin.top:3005/api/getgoods?pageindex="+this.pageindex).then(result => {
                if(result.body.status===0){
                    console.log(result.body);
                    this.goodsList=this.goodsList.concat(result.body.message);
                }
            });
        },
        getmore(){
            this.pageindex++;
            this.getGoodsList();
        }
    }

}
</script>
<style lang="less" scoped>
.goodslist-container {
    display: flex;
    flex-wrap: wrap;
    padding: 6px;
    justify-content: space-between;

    .goodsitem {
        width: 49%;
        border: 1px solid #ccc;
        box-shadow: 0 0 6px #ccc;
        margin-bottom: 6px;
        display: flex;
        flex-direction:column;
        justify-content:space-between;
        min-height: 293px;
    }

    img {
        width: 100%;
        display: block;

    }

    h1 {
        font-size: 12px;
    }

    .goodsinfo {
        padding: 0px 3px;
        background-color: #eee;

        .price {
            .newPrice {
                font-size: 16px;
                font-weight: bold;
                color: red;
            }

            .oldPrice {
                font-size: 12px;
                text-decoration: line-through;
                margin-left: 5px;
            }
        }

        .sell {
            display: flex;
            justify-content: space-between;
            font-size: 12px;
        }

        p {
            margin-bottom: 0px;
        }
    }
}
</style>